//
//  AccountViewController.swift
//  PhotoLine
//
//  Created by 吴帅 on 2017/11/20.
//  Copyright © 2017年 PhotoLine. All rights reserved.
//

import UIKit
import WSCarousel

class AccountViewController: BaseViewController {

    var show: Bool = true;
    lazy var carouselView: WSCarouselView = {
        () -> WSCarouselView in
        var info:CarouselInfo = CarouselInfo.init(collectionViewName: "WSCollectionViewCell",
                                                  itemSize: CGSize.init(width: 300, height: 400),
                                                  minimumSpacing: 10,
                                                  scrollDirection: UICollectionViewScrollDirection.horizontal,
                                                  datas: ["", "", ""]);
        info.backgroudColor = ThemeColor;
        let carouselView = WSCarouselView.init(frame: CGRect.init(x: (SCREEN_WIDTH-300)/2.0, y: 0, width: 300, height: 450), carouselInfo: info);
        return carouselView;
    }()
    
    lazy var acctionView : AccountView = {
        () -> AccountView in
        let view = AccountView.init(frame: CGRect.init(x: 20, y: 500, width: SCREEN_WIDTH-40, height: SCREEN_HEIGHT-400))
        view.layer.cornerRadius = CORNERRADIUS;
        return view;
    }()
    
    // MARK: - LiftCycle
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated);
        UIView.animate(withDuration: 0.5) {
            self.showView(show: true);
        };
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor = ThemeColor;
        self.view.addSubview(self.carouselView);
        self.view.addSubview(self.acctionView);
        
        self.acctionView.signInButton.addTarget(self, action: #selector(AccountViewController.signIn), for: UIControlEvents.touchUpInside);
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // MARK: - UITableViewDataSource
    
    // MARK: - Private
    func signIn() {
        UIView.animate(withDuration: 0.5, animations: {
            self.showView(show: false);
        }) { (status) in
            let loginVC = LoginController.init();
            let navc = NavigationController.init(rootViewController: loginVC);
            self.present(navc, animated: false, completion: {
                loginVC.setupTableViewFrame(animate: true);
            });
        };
    }
    
    func showView(show: Bool) {
        if self.show==show {
            return;
        }
        self.show = show;

        if show {
            self.carouselView.alpha = 1;
            self.acctionView.frame.origin.y = 500;
        } else {
            self.carouselView.alpha = 0;
            self.acctionView.frame.origin.y = SCREEN_HEIGHT;
        }
    }
    // MARK: - Public

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
